package main

import "fmt"

// Author : CSR丶WARRIOR
// Time ： 2020/10/14  11:19
// TOOLS : GoLand
// FILENAME : Select sort.go
// STATEMENT: 选择排序

func main() {
	s := []int{4, 3, 6, 5, 11, 34}
	selectSort(s)
	fmt.Println(s) //[3 4 5 6 11 34]
}

func selectSort(s []int) {
	for i := 0; i < len(s)-1; i++ {
		min := s[i]
		var index int
		for j := i; j < len(s); j++ {
			if s[j] < min {
				min = s[j]
				index = j
			}
		}
		if s[i] > min {
			temp := s[i]
			s[i] = min
			s[index] = temp
		}
	}
}
